package com.aurora.controller;

import com.aurora.model.vo.ResultVO;
import com.aurora.neo4j.entity.RelationVo;
import com.aurora.neo4j.service.PersonService;
import com.aurora.service.RedisService;
import com.aurora.service.TopicService;
import com.aurora.spider.utils.SpiderUtil;
import org.neo4j.ogm.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @program: blog-aurora
 * @description: 对外api 无权限校验
 * @author: jonk
 * @create: 2023-08-04 15:48
 **/

@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    TopicService topicService;

    @Resource
    SpiderUtil spiderUtil;
    @Autowired
    RedisService redisService;

    @Resource
    PersonService personService;

    @RequestMapping("/findStarByName")
    public ResultVO<Result> findStarByName() {
        //查询二级关系
        String name ="成龙";
        int limit =10;
        RelationVo vo =personService.findStarByName(name,limit);
        String cql = " MATCH (n:Person) RETURN n LIMIT 25";
        Result result = personService.queryByCypher(cql);
        return ResultVO.ok(result);

    }
    @RequestMapping("/initTopic")
    public String initTopic() {
//        FileReader fileReader = new FileReader("D:\\dev\\space\\blog-aurora\\src\\main\\java\\com\\aurora\\spider\\gitee\\star.txt");
//        List<String> list = fileReader.readLines();
//        List<Topic> topicList = list.stream().map(item -> {
//            Topic topic = new Topic();
//            topic.setTopicName(item);
//            return topic;
//        }).collect(Collectors.toList());
//        List<Topic> topicList1 = topicList.stream().filter(item -> StringUtils.isNotBlank(item.getTopicName().trim())).collect(Collectors.toList());
//        boolean b = topicService.saveBatch(topicList1);

//        redisService.set("createPersonRelationByName", 0);
//        redisService.set("createPersonRelation", 0);
//        redisService.set("houyuantuanEvent", 0);
//        //初始化数据
//        spiderUtil.houyuantuan();
        spiderUtil.macysSearch();
        return " sucess ";
    }

}